// pages/index/index.js
<<<<<<< HEAD
const {dateCartoon}=require('../../data/updateCartoon');
const {result}=require('../../data/recommend');
const recommend = require('../../data/recommend');
const modules=result.modules;
let episodes=dateCartoon.map(res=>{
  let obj={
    day_of_week:res.day_of_week,
    cartoon_of_day:res.episodes
  }
  // let arr=[];
  // arr.push(obj);
  return obj;
});
const db=wx.cloud.database();
const plays=db.collection('plays');
=======
>>>>>>> 0f2c98aa9d4bcf9620f3cf407037a68e3291d28a
Page({

  /**
   * 页面的初始数据
   */
  data: {
<<<<<<< HEAD
    voiceList:[],
    chaseWeek:['一','二','三','四','五','六','日'],
    episodes,
    category:['搞笑','热血','奇幻','励志','萌系','运动'],
    activeTitle:3,
    todayOfWeek:3,
    ani:'',
    n:[1,1],
    recommendShow:[],
    recommendShowMy:[]
  },
  async addmoreAfter(){
    const index=this.data.voiceList.length;
    if(index>=this.total){
      wx.showToast({
        title: '没有更多数据',
        icon:'none'
      })
      return ;
    }
    wx.showToast({
      title: '加载中',
      icon:'loading',
      duration:1000
    })
    let {data:voiceList}=await plays
    .skip(index)
    .limit(20)
    .get()
    this.setData({
      voiceList:[...this.data.voiceList,...voiceList]
    })
  },
  async addmoreBefore(){
    const index=this.data.voiceList.length;
    if(index>=this.total){
      wx.showToast({
        title: '没有更多数据',
        icon:'none'
      })
      return ;
    }
    wx.showToast({
      title: '加载中',
      icon:'loading',
      duration:1000
    })
    let {data:voiceList}=await plays
    .skip(index)
    .limit(20)
    .get()
    this.setData({
      voiceList:[...voiceList,...this.data.voiceList]
    })
  },
  gotoCartoon(e){
    let seasonId=e.currentTarget.dataset.seasonid;
    console.log(seasonId);
    wx.navigateTo({
      url: '../cartoon/cartoon?seasonId=seasonId',
    })
  },
  gotoClassify(){
    wx.navigateTo({
      url: '../classify/classify',
    })
  },
  gotoSearch(){
    wx.navigateTo({
      url: '../search/search',
    });
  },
  gotoDetail(){
    wx.navigateTo({
      url: '../play/play?id=BV2vM4y1N79U',
    })
  },
  tabChange(e){
    let activeTitle=e.detail.index;
    this.setData({
      activeTitle
    })
  },
  changeRecommend(e){
    // console.log(e);
    let id=e.currentTarget.dataset.id;
    let [n1,n2]=this.data.n;
    // console.log(n1,n2);
    let n=this.data.n[id-1];
    if(n>6){
      n=0;
    }
    const recommend=modules[id].items;
    let recommendShow=recommend.slice(n*3,n*3+3);
    // console.log(id,n);
    this.Rotate(n);
    if(id==1){
      this.setData({
        recommendShow,
        n:[n+1,n2]
      })
    }
    else{
      this.setData({
        recommendShowMy:recommendShow,
        n:[n1,n+1]
      })
    }
  },
  Rotate(n){
    let animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear',
      delay: 0
    });
    animation.rotate(180*n).step();
    this.setData({
      ani:animation.export()
    });
  },
=======

  },

>>>>>>> 0f2c98aa9d4bcf9620f3cf407037a68e3291d28a
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
<<<<<<< HEAD
    const {dateCartoon}=require('../../data/updateCartoon');
    const recommend = require('../../data/recommend');
    const modules=result.modules;
    let episodes=dateCartoon.map(res=>{
      let obj={
        day_of_week:res.day_of_week,
        cartoon_of_day:res.episodes
      }
      // let arr=[];
      // arr.push(obj);
      return obj;
    });
    this.setData({
      episodes,
      recommendShow:modules[1].items.slice(-3),
      recommendShowMy:modules[2].items.slice(-3),
    });
=======

>>>>>>> 0f2c98aa9d4bcf9620f3cf407037a68e3291d28a
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
<<<<<<< HEAD
    this.datebar();
    this.setvoicedata();
  },
  datebar(){
    // console.log(episodes)
    const firstepisodes=this.data.episodes;
    // console.log(firstepisodes);
    let episodes=[];
    let todayOfWeek=new Date().getDay();
    // console.log(todayOfWeek);
    for(let i=0;i<7;i++){
      let j=(i+todayOfWeek+4)%7;
      // console.log(i,j);
      episodes.push(firstepisodes[j]);
    }
    this.setData(
      {
        episodes
      }
    )
  },
  async setvoicedata(){
    let res=await plays
    .limit(20)
    .get();
    this.voiceList=res.data;
    this.total=(await plays.count()).total;
    this.setData({
      voiceList:this.voiceList
    })
=======

>>>>>>> 0f2c98aa9d4bcf9620f3cf407037a68e3291d28a
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
<<<<<<< HEAD
  onShareAppMessage: function (e) {
    // console.log(e);
    let title=e.target.dataset.title;
    let imageUrl=e.target.dataset.imageurl;
    let id=e.target.dataset.playid;
      return{
       title,
       imageUrl,
       path:
      "/pages/play/play?id="+id
       }
=======
  onShareAppMessage: function () {

>>>>>>> 0f2c98aa9d4bcf9620f3cf407037a68e3291d28a
  }
})